package chapter4.eg11;

import com.alibaba.fastjson.JSON;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import org.apache.kafka.common.serialization.Serializer;

public class UserSerializer implements Serializer<User> {

  @Override
  public void configure(Map<String, ?> configs, boolean isKey) {

  }

  @Override
  public byte[] serialize(String topic, User data) {
    System.out.println("start serialize");
    try {
      return JSON.toJSONString(data).getBytes(StandardCharsets.UTF_8);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }

  @Override
  public void close() {

  }
}
